<template>
	<view class="index">
		<view class="DengLuFangShi">
			<view
				@click="DianJi_DengLu_FangShi('MiMa')"
				:class="DengLu_FangShi=='MiMa'?'Hover':''">密码登陆</view>
			<view
				@click="DianJi_DengLu_FangShi('YanZhengMa')"
				:class="DengLu_FangShi=='YanZhengMa'?'Hover':''">验证码登陆</view>
		</view>
		<view class="XunHuan">
			<view class="Zuo">账号类型</view>
			<view class="You DanXuan">
				<radio-group @change="DanXuan_ZhangHaoLeiXing">
					<label v-if="FaXin_ZhuangTai_YouXiang">
						<radio :checked="ZhangHao_LeiXing == 'email'" value="email" /><text>邮箱</text>
					</label>
					<label v-if="FaXin_ZhuangTai_ShouJi">
						<radio :checked="ZhangHao_LeiXing == 'phone'" value="phone" /><text>手机</text>
					</label>
				</radio-group>
			</view>
		</view>
		<view class="BiaoDan">
			<template v-if="DengLu_FangShi == 'YanZhengMa'">
				<view class="XunHuan">
					<text
						:class="ZhangHao_LeiXing=='email'?'iconfont icon-fuzhi':'iconfont icon-shouji'"></text>
					<input
						v-model="Vmodel_ZhangHao"
						:type="ZhangHao_LeiXing=='email'?'text':'number'"
						:placeholder="ZhangHao_LeiXing=='email'?'请输入邮箱地址':'请输入手机号'"
						placeholder-style="color:#C0C4CC;">
					<view
						v-if="FaMa_ZhuangTai == 'WeiFaSong'"
						@click="DianJi_FaMa(ZhangHao_LeiXing=='email'?'email':'sms')">发送验证码</view>
					<view
						v-if="FaMa_ZhuangTai == 'JieShouZhong'"
						class="Bj-ChangGuiSe"
						style="color: #FFF;background: #606266;">{{FaMa_DaoJiShi}}秒后重发</view>
				</view>
				<view class="XunHuan">
					<text class="iconfont icon-keyboard-9"></text>
					<input
						v-model="Vmodel_MiMa"
						placeholder="输入验证码"
						placeholder-style="color:#C0C4CC;">
				</view>
				<view
					@click="DianJi_DengLu('YanZhengMa')"
					class="YouRan-UI-AnNiu-1 Flex Bj-LanSe"
					style="margin: 25rpx auto 0 auto;">验证码登陆</view>
			</template>
			<template v-if="DengLu_FangShi == 'MiMa'">
				<view class="XunHuan">
					<text class="iconfont icon-user"></text>
					<input
						v-model="Vmodel_ZhangHao"
						:type="ZhangHao_LeiXing=='email'?'text':'number'"
						:placeholder="ZhangHao_LeiXing=='email'?'输入邮箱地址':'请输入手机号'"
						placeholder-style="color:#C0C4CC;">
				</view>
				<view class="XunHuan">
					<text class="iconfont icon-lock"></text>
					<input
						v-model="Vmodel_MiMa"
						type="text"
						placeholder="输入密码"
						placeholder-style="color:#C0C4CC;">
				</view>
				<view
					@click="DianJi_DengLu('MiMa')"
					class="YouRan-UI-AnNiu-1 Flex Bj-LanSe"
					style="margin: 25rpx auto 0 auto;">账号登陆</view>
			</template>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				DengLu_FangShi:"MiMa",
				ZhangHao_LeiXing:"email",
				Vmodel_ZhangHao:"",
				Vmodel_MiMa:"",
				
				FaMa_ZhuangTai:"WeiFaSong",
				FaMa_DaoJiShi:60,
				
				
				FaXin_ZhuangTai_YouXiang:true,
				FaXin_ZhuangTai_ShouJi:true,
			}
		},
		onLoad() {
			uni.request({
				url:this.$_URL() + "/api/v2/global/configs",
				method:'GET',
				header:this.$_Fresns_Header(),
				data:{
					"keys":"site_email_login,site_phone_login"
				},
				success: (res) => {
					this.FaXin_ZhuangTai_YouXiang = res.data.data.site_email_login;
					this.FaXin_ZhuangTai_ShouJi = res.data.data.site_phone_login;
				}
			})
		},
		methods: {
			// 点击，登陆，方式
			DianJi_DengLu_FangShi(e){
				this.DengLu_FangShi = e;
			},
			// 单选，账号类型
			DanXuan_ZhangHaoLeiXing(e){
				this.ZhangHao_LeiXing = e.target.value
			},
			// 点击，发码
			DianJi_FaMa(e){
				uni.showLoading({ title:"验证码发送中" });
				uni.request({
					url:this.$_URL() + "/api/v2/common/send-verify-code",
					method:'POST',
					header:this.$_Fresns_Header(),
					data:{
						"type":e,
						"useType":2,
						"templateId":7,
						"account":this.Vmodel_ZhangHao,
						"countryCode":e=='email'?'':86,
					},
					success: (res) => {
						uni.hideLoading();
						if(res.data.code == 0){
							this.FaMa_ZhuangTai = 'JieShouZhong';
							this.DingShiQi_ShiJian = setInterval(() => {
								this.FaMa_DaoJiShi -= 1;
								if(this.FaMa_DaoJiShi == 0){
									clearInterval(this.DingShiQi_ShiJian)
									this.FaMa_DaoJiShi = 60;
									this.FaMa_ZhuangTai = 'WeiFaSong';
								}
							}, 1000);
						}else{
							uni.showToast({
								title:res.data.message,
								icon:"none",
								duration:1000
							});
						}
					}
				})
			},
			// 点击，登陆
			DianJi_DengLu(e){
				if(e=='YanZhengMa'){
					uni.showLoading({ title: "登录中" });
					uni.request({
						url:this.$_URL() + "/api/v2/account/login",
						method:'POST',
						header:this.$_Fresns_Header(),
						data:{
							"type":this.ZhangHao_LeiXing, // 账号类型：email,phone
							"account":this.Vmodel_ZhangHao, // 邮箱地址 / 手机号码
							"countryCode":86, // 国际区号
							"verifyCode":this.Vmodel_MiMa, // 验证码登陆
						},
						success: (res) => {
							uni.hideLoading();
							if(res.data.message == '成功'){
								uni.setStorageSync("ZhangHaoXinXi",res.data);
								this.$_TiaoZhuan("WoDe/WoDe_DengLu_YongHuXuanZe")
							}else{
								uni.showToast({
									title:res.data.message,
									icon:"none",
									duration:1000
								});
							}
						}
					})
				}
				if(e=='MiMa'){
					uni.showLoading({ title: "登录中" });
					uni.request({
						url:this.$_URL() + "/api/v2/account/login",
						method:'POST',
						header:this.$_Fresns_Header(),
						data:{
							"type":this.ZhangHao_LeiXing, // 账号类型：email,phone
							"account":this.Vmodel_ZhangHao, // 邮箱地址 / 手机号码
							"countryCode":86, // 国际区号
							"password":this.$_ZiFuChuan_Zhuan_base64(this.Vmodel_MiMa), // 密码
							"verifyCode":"", // 验证码登陆
						},
						success: (res) => {
							uni.hideLoading();
							if(res.data.message == '成功'){
								uni.setStorageSync("ZhangHaoXinXi",res.data);
								this.$_TiaoZhuan("WoDe/WoDe_DengLu_YongHuXuanZe")
							}else{
								uni.showToast({
									title:res.data.message,
									icon:"none",
									duration:1000
								});
							}
						}
					})
				}
			},
		}
	}
</script>

<style lang="scss">
.index {
	view{
		font-size: 28rpx;
	}
	.DengLuFangShi{
		margin: 50rpx auto 50rpx auto;
		border: 1rpx solid $BianKuangSe;
		width: 600rpx;
		height: 80rpx;
		border-radius: 100rpx;
		display: flex;
		align-items: center;
		overflow: hidden;
		view{
			width: 50%;
			height: 80rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: $ZhanWeiSe;
		}
		.Hover{
			background: $BeiJingSe;
			color: $YuanSe;
		}
	}
	.XunHuan{
		display: flex;
		border: 1rpx solid $BianKuangSe;
		margin: 25rpx 25rpx 0 25rpx;
		height: 80rpx;
		.Zuo{
			font-size: 22rpx;
			line-height: 22rpx;
			background: $BeiJingSe;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-shrink: 0;
			padding: 0 25rpx;
			border-right: 1rpx solid $BianKuangSe;
		}
		.You{
			flex: 1;
			height: 80rpx;
		}
		.DanXuan{
			height: 80rpx;
			display: flex;
			align-items: center;
			radio-group{
				display: flex;
				align-items: center;
				label{
					display: flex;
					align-items: center;
					margin: 0 0 0 15rpx;
					radio{
						transform: scale(0.6);
						margin: 0 -10rpx 0 0;
					}
				}
			}
		}
	}
	.BiaoDan{
		.XunHuan{
			display: flex;
			align-items: center;
			padding: 25rpx;
			border-bottom: 1rpx solid $BianKuangSe;
			text{
				color: $ZhanWeiSe;
				margin: 0 15rpx 0 0;
			}
			input{
				font-size: 28rpx;
				flex: 1;
			}
			view{
				margin: 0 0 0 15rpx;
				display: inline-flex;
				background: $HuangSe;
				color: #000;
				font-size: 22rpx;
				line-height: 22rpx;
				border-radius: 100rpx;
				padding:15rpx 20rpx;
			}
		}
	}
}
</style>